clear
capture log close
set more off
set mem 500m


**** 

use data_pt_pop_1891, clear

*** Fix manchester and salford
replace loc="manchester" if loc=="salford"
count
collapse (sum) pop, by(loc year)
count

sort loc

merge loc using data_town_cotton_shr_1851

tab _merge
keep if _merge==3
drop _merge


** LHS var
gen ln_pop=ln(pop)


** RHS var
gen cotton10=0
replace cotton10=1 if shr_cot>.1


***************************
gen np=-pop
sort year np 
by year: gen rank=_n

*** Log rank with Gabaix-Ibragimov correction
gen ln_rank_cor=ln(rank-0.5)


*** Outsheet for graphing
keep loc year ln_pop cotton10 ln_rank_cor

reshape wide ln_pop ln_rank_cor, i(loc) j(year)

sort cotton10
outsheet using results_figure_A3_A4_A5_zipfs_graphs_data.csv, comma names replace




